package com.qf.sms.exception;


import java.lang.reflect.Field;

/**
 * 自定义异常，短信发送异常
 * @version v1.0.0
 * @Description:
 * @author: 姜红凯
 * @date: 2022.04.11
 * @since 1.0
 */
public class SmsSendException extends Exception{
    private int errorCode;
    private int type=0;
    public static final int TENCENT_SMS=1;
    public static final int ALIBABA_SMS=2;
    public static final String TENCENT_SMS_MSG="调用腾讯短信失败";
    public static final String ALIBABA_SMS_MSG="调用阿里短信失败";
    public SmsSendException(String mag){
        super(mag);
    }
    public SmsSendException(int code,String mag){
        super(mag);
        this.errorCode=code;
    }
    public SmsSendException(int code){
        this.errorCode=code;
        Class<SmsSendException> clazz=SmsSendException.class;
        Field message=null;
        try {
            message= clazz.getDeclaredField("detailMessage");
            message.setAccessible(true);
            switch (errorCode){
                case TENCENT_SMS:message.set(this,TENCENT_SMS_MSG); break;
                case ALIBABA_SMS:message.set(this,ALIBABA_SMS_MSG); break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @Override
    public void printStackTrace() {
        System.err.println(this.getMessage());
    }
}
